package com.totoro.mall.mall_buyer.utils;

import com.totoro.mall.mall_buyer.enums.CodeEnum;

/**
 * 枚举工具类，根据枚举的Code获取枚举对象
 * Created by Niki on 2018/4/23 8:29
 */
public class EnumUtil {
    public static <T extends CodeEnum> T getByCode(Integer code, Class<T> enumClass) {
        for (T each : enumClass.getEnumConstants()) {
            if (code.equals(each.getCode())) {
                return each;
            }
        }
        return null;
    }
}
